package 程序员面试金典;

import org.junit.Test;

import java.util.Arrays;

public class 珠玑妙算 {

    public int[] masterMind(String solution, String guess) {
         int a=0,b=0;
        for (int i = 0; i < solution.length(); i++) {
            if (solution.charAt(i)==guess.charAt(i))
                a++;
        }
        char[] solutions = solution.toCharArray();
        char[] guesss = guess.toCharArray();
        Arrays.sort(solutions);
        Arrays.sort(guesss);
        for (int i = 0; i < solution.length(); i++) {
            for (int j = 0; j < solution.length(); j++) {
                if (guesss[i]==solutions[j]){
                    b++;
                    solutions[j]='.';
                    break;
                }
            }
        }
        return new int[]{a,b-a};
    }
    @Test
    public void test(){
        String s="abc";
        char[] chars = s.toCharArray();
        chars[0]='0';
        System.out.println(new String(chars));
    }
}
